<?php

namespace Biz\Libraries;

use Lumen\Core\Exceptions\BusinessException;

/**
 * TranslationUtil.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class TranslationUtil
{
    /**
     * 转换Form表单translations节点数据平铺到$data数组中.
     *
     * @param array $data
     *
     * @throws BusinessException
     *
     * @return array
     */
    public static function convertTranslationsData(array $data): array
    {
        if (! isset($data['translations'])) {
            throw new BusinessException('数组中必须包含 translations 节点');
        }

        $translations = $data['translations'];
        foreach ($translations as $key => $value) {
            $data[$key] = $value;
        }
        unset($data['translations']);

        return $data;
    }
}
